# Maintainer: Antoni Aloy <aaloytorrens@gmail.com>
pkgname=gzdoom
pkgver=4.8.2
pkgrel=0
pkgdesc="Feature centric port for all Doom engine games"
url="https://www.zdoom.org/"
# ppc64le blocked by zmusic
# x86 blocked by sse2
# riscv64 fails to build, link-make applet not found
# 32-bit builds blocked by src/common/engine/i_interface.cpp:4:29 (error: static assertion failed: 32 builds are not supported)
arch="all !ppc64le !x86 !riscv64 !armv7 !armhf"
license="GPL-3.0-or-later"
depends="fluidsynth"
makedepends="
	bzip2-dev
	cmake
	fts-dev
	gtk+3.0-dev
	libexecinfo-dev
	libgme-dev
	libjpeg-turbo-dev
	libsndfile-dev
	libvpx-dev
	mesa-dev
	mpg123-dev
	nasm
	openal-soft-dev
	samurai
	sdl2-dev
	vulkan-loader-dev
	zlib-dev
	zmusic-dev
	"
subpackages="$pkgname-doc"

source="
	https://github.com/coelckers/gzdoom/archive/refs/tags/g$pkgver.tar.gz
	0001-link-zipdir-against-fts.patch
	0002-fix-musl-fts.patch
	0003-define-cpu_set_t.patch
	"
builddir="$srcdir/$pkgname-g$pkgver"
options="!check" # No test suite

# Enable openmp when possible
case "$CARCH" in
s390x)
	_no_openmp=ON
	;;
*)
	makedepends="$makedepends openmp-dev"
	_no_openmp=OFF
	;;
esac

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_SHARED_LIBS=True \
		-DDYN_GTK=OFF \
		-DDYN_OPENAL=OFF \
		-DNO_OPENMP=$_no_openmp \
		$CMAKE_CROSSOPTS
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
5f94aca016e87c8284b41d5c3beaeb752a4201e4562a528375addc976c7d7163d23a4885a223e4377856a2b75b71179efa80e99baf3edfe87fa19cf1e8bbfa42  g4.8.2.tar.gz
7e2f5e593cabf618c2e5c520380af01ba4aa3fef9955a6305888d2bb017af25579ee02bd16b6c6080ac4e823498b224edb553f998b8a6d7833d4789070931c38  0001-link-zipdir-against-fts.patch
7fed60cb9006653c9a85c226e98efae02b3f7f6bd34c47db03f29bc98bf1584f7e128394ab920956d799efa6bace3605f628fd806e130410243e3fdc78b417bc  0002-fix-musl-fts.patch
507a8297823856348eacc1adc62f99d01c4bcf90d94c0ba4517b94d9d6adccbfaeec67588303bbb37eca03d3f2033fd060d034db433f35484e39d8dd4ff8773a  0003-define-cpu_set_t.patch
"
